/** file FilterOctave.cpp
    author belot.nicolas
*/

#include "FilterOctave.h"
#include <cmath>
namespace libtrckr {
	string FilterOctave::HowToTune(){
		return "Spin 1 2; Spin -10 0";

	}


	FilterOctave::FilterOctave():ratio(0), count(0){

	}
	FilterOctave::FilterOctave(const FilterOctave& f):ratio(f.ratio),count(f.count){

	}

	FilterOctave::~FilterOctave(){

	}

	void FilterOctave::Tune(DynArray<int> conf){
		count=conf[0];
		ratio=pow(10.0, conf[1]/20.0);
	}

	void FilterOctave::Init(){
		//do nothing
	}

	Buffer &FilterOctave::Preview(Buffer &b){
		for(uint i=0;i<b.size();i++){
			if(count==1){
				if(b[i]<0.){
					b[i]+= -(b[i]*ratio);
				}
			}else if(count==2){
				if(b[i]<0.){
					b[i]+= -(b[i]*ratio);
				}
				//we get first octave
				if(b[i]>0.5){
					b[i]+= (-b[i]*ratio);
				}
			}
		}		

	}

	double *FilterOctave::Preview(double*data, int size){
		for(uint i=0;i<size;i++){
			if(count==1){
				if(data[i]<0.){
					data[i]+= -(data[i]*ratio);
				}
			}else if(count==2){
				if(data[i]<0.){
					data[i]+= -(data[i]*ratio);
				}
				//we get first octave
				if(data[i]>0.5){
					data[i]+= (-data[i]*ratio);
				}
			}
		}		
	}



	Buffer &FilterOctave::Execution(Buffer &b){
		return Preview(b);
	}

	double *FilterOctave::Execution(double*data, int size){
		return Preview(data,size);
	}





}
